﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcEmrRazor.Controllers
{
    public class LeftNavController : Controller
    {
        //
        // GET: /LeftNav/

        [ChildActionOnly]
        public ViewResult Index()
        {
            return View();
        }
        [ChildActionOnly]
        public string LeftMenu()
        {            
            //var urlHelper = new UrlHelper(helper.ViewContext.RequestContext); 
            if (System.Web.HttpContext.Current.Session["user"] == null)
            {
                return "";
            }

            var urlHelper = new UrlHelper(HttpContext.Request.RequestContext);
            
            var builderDiv = new TagBuilder("div");
            builderDiv.MergeAttribute("id", "menu");
            
            var builderUL = new TagBuilder("ul");
            
            var builderLi = new TagBuilder("li");            
            var builderH2 = new TagBuilder("h2");
            builderH2.InnerHtml = "Manage Patients";
            builderLi.InnerHtml += builderH2.ToString();
            builderUL.InnerHtml += builderLi.ToString();

            builderUL.InnerHtml += CreateMenuLi(urlHelper, "Index", "Home", "Home/Search for patient(s)");
            builderUL.InnerHtml += CreateMenuLi(urlHelper, "Index", "Demographics/Create", "Add new patient");

            if (System.Web.HttpContext.Current.Session["DemographicID"] != null)
            {
                var builderUL2 = new TagBuilder("ul");

                var builderLi2 = new TagBuilder("li");
                var builderH22 = new TagBuilder("h2");
                builderH22.InnerHtml = "Procedures";
                builderLi2.InnerHtml += builderH22.ToString();
                builderUL2.InnerHtml += builderLi2.ToString();

                builderUL2.InnerHtml += CreateMenuLi(urlHelper, "Index", "Problems", "Problems");
                builderUL2.InnerHtml += CreateMenuLi(urlHelper, "Index", "Smoking", "Smoking");

                builderDiv.InnerHtml = builderUL.ToString() + builderUL2.ToString();
            }
            else
            {
                builderDiv.InnerHtml = builderUL.ToString();
            }

            string s2 = builderDiv.ToString(TagRenderMode.SelfClosing);
            s2 = builderDiv.ToString();
            return s2;

            //string s = "<div id=\"menu\"><ul><li><h2>CSS Drop Down Menus</h2><ul><li><a href=\"../css-dropdown-menus.html\" title=\"tanfa Introduction\">Intro for CSS Enthusiasts</a></li><li><a href=\"index.html\" title=\"Plain HTML Code\">Demonstration HTML</a></li><li><a href=\"http://www.xs4all.nl/~peterned/csshover.html\" title=\"whatever:hover file\">csshover.htc file</a></li></ul></li></ul></div>";
            //return s;
        }
        private string CreateMenuLi(UrlHelper urlHelper, string action, string controller, string title)
        {
            var builderLiInner = new TagBuilder("li");
            var builderAInner = new TagBuilder("a");
            builderAInner.MergeAttribute("href", urlHelper.Action(action, controller));
            builderAInner.MergeAttribute("title", title);
            builderAInner.SetInnerText(title);
            builderLiInner.InnerHtml = builderAInner.ToString();
            return builderLiInner.ToString();
        }
    }
}
